home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
xmmlrg.exe
/
XMMHNDLR.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-09-05
|
17KB
|
448 lines
/*************************************************************************
* *
* XMMHandler - Access XMM for storing / accessing db_Vista records *
* *
* This file implements the routines that the user calls. This library *
* calls the modified XMM routines (for large model) as distributed by *
* Microsoft. *
* *
* Author: Tom Frank, BIMCO *
* *
*************************************************************************/
#ifndef LINT_ARGS
#define LINT_ARGS
#endif
#ifndef ANSI
#define ANSI
#endif
#include "xmm.h"
#include "xmmhndlr.h"
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
/*************************************************************************
* *
* Defines used to return error codes - these match the db_Vista *
* conventions - here so we don't need vista.h *
* *
*************************************************************************/
#define S_OKAY 0
#define S_NOTFOUND 2
/*************************************************************************
* *
* Defines used within this module *
* *
*************************************************************************/
#define TRUE 1
#define FALSE 0
#define UNUSED -1
#define ONE_K 1024L
#define MAX_REC_LEN 256
/*************************************************************************
* *
* Data Structure Definitions that are not visible outside this module *
* *
*************************************************************************/
typedef struct _XMMHandle { /* XMM handle data structure */
short handle; /* XMM handle */
int adj_rec_size; /* user's rounded record size */
int act_rec_size; /* user's actual record size */
long max_rec_alloc; /* highest rec # alloc */
long max_rec_used; /* highest rec # used */
} XMMHandle, *XMMHandlePTR;
/*************************************************************************
* *
* Global Data Available from this module *
* *
*************************************************************************/
int XMMErrorCode; /* return code from XMM rtns */
/*************************************************************************
* *
* Local Data Storage - internal to this module *
* *
*************************************************************************/
static XMMHandlePTR XMM_Handle_Table; /* pointer to handle table */
static int initialized = FALSE; /* started?? */
static int Max_Handle_Alloc; /* User requested max handles */
static int Max_Handle_Used; /* last handle used */
static char move_area[MAX_REC_LEN]; /* for data movement */
/*************************************************************************
* *
* Local Functions internal to this module *
* *
*************************************************************************/
static int null_record(char *buffer, int buff_len);
/*<f>*/
int InitXMMSystem(int MaxHandles)
/*************************************************************************
* *
* Initialize the XMM interface system - return TRUE / FALSE to signify *
* our success level *
* *
*************************************************************************/
{
int i;
if (initialized) /* already done?? */
return (S_NOTFOUND); /* yes */
if (!XMM_Installed()) /* is XMM handler around?? */
return (S_NOTFOUND); /* no */
if ((XMM_Handle_Table=(XMMHandlePTR)malloc(sizeof(XMMHandle) * MaxHandles)) == NULL)
return (S_NOTFOUND); /* no memory */
memset((char *)XMM_Handle_Table, '\0', sizeof(XMMHandle) * MaxHandles);
for (i=0; i < MaxHandles; i++) /* set all as unused */
XMM_Handle_Table[i].handle = UNUSED;
initialized = TRUE; /* started now */
Max_Handle_Alloc = MaxHandles; /* User requested max handles */
Max_Handle_Used = -1; /* last handle used (none yet) */
return (S_OKAY);
}
/*<f>*/
int ShutXMMSystem(void)
/*************************************************************************
* *
* Close down the XMM interface system - return S_OKAY / S_NOTFOUND to *
* signify our success level *
* *
*************************************************************************/
{
int i;
if (!initialized) /* already done?? */
return (S_NOTFOUND); /* yes */
/*************************************************************************
* *
* Insure all Handles have been released *
* *
*************************************************************************/
for (i=0; i <= Max_Handle_Used; i++)
{
if (XMM_Handle_Table[i].handle != UNUSED) /* in use?? */
XMM_FreeExtended(XMM_Handle_Table[i].handle);
}
/*************************************************************************
* *
* Drop memory for Handle Table *
* *
*************************************************************************/
free(XMM_Handle_Table);
/*************************************************************************
* *
* Reset Flags *
* *
*************************************************************************/
initialized = FALSE; /* not started now */
return (S_OKAY);
}
/*<f>*/
XHandle AllocateXMMArea(long MaxRecs, int RecSize)
/*************************************************************************
* *
* Allocate an XMM area and return the handle to the user. A negative *
* return is an error and the actual error (if -3) is in XMMErrorCode *
* *
* Note: we allocate 1 more record than MaxRecs since 0 is a valid recno *
* *
*************************************************************************/
{
unsigned space_needed;
long ret_code;
XHandle hnd;
struct XMM_Move CtrlBlk;
char block[ONE_K];
int i;
int adj_recsize;
XMMErrorCode = 0; /* clear code */
if (!initialized) /* started?? */
return (-1); /* no */
for (hnd=-1,i=0; i < Max